
$("#set").click(function(){
	window.location.href="html/set.html";
});
$("#para").click(function(){
	window.location.href="html/para.html";
});
$("#button").click(function(){
	window.location.href="button.html";
});
$("#adj").click(function(){
	window.location.href="adj.html";
});
$("#ntp").click(function(){
	window.location.href="ntp.html";
});
$("#weather").click(function(){
	window.location.href="weather.html";
});
$("#others").click(function(){
	window.location.href="others.html";
});
$("#wifiset").click(function(){
	var ssid = prompt('名称');
	if (ssid != null && ssid != '') {
		console.log(ssid);
		var pwd = prompt('密码');
		if (pwd != null && pwd != '' && pwd.length >= 8) {
			console.log(pwd);
			$.post("/wificfg", "ssid:"+ssid+";pwd:"+pwd+';',function(ret){
				console.log(ret);
			});
		}
	}
}
);

var upgrading = false;
$("#fota").click(function(){
	if (window.confirm('升级？')){
		$.post("/rst", "ota",function(ret){
			upgrading = true;
		});
		return true;
	}else{
		
		return false;
	}
});
setInterval(function(){
	if (upgrading == true) {
		$.get("/otaInfo", "",function(ret){
			console.log(ret);
			var valArr = ret.split(',');
			if (valArr[1] != '0') {
				if (valArr[1] == valArr[0]) {
					$('#otainfo').text('FOTA完成，请点击重启');
					upgrading = false;
				}
				else {
					$('#otainfo').text('FOTA  [' + valArr[0] + '/' + valArr[1] + '(' + parseInt(valArr[0]/valArr[1]*100) +'%) ]');
				}
			}
			else {
				$('#otainfo').text('FOTA准备中');
			}
		});
	}
}, 100);

$("#rst").click(function(){
	if (window.confirm('重启？')){
		$.post("/rst", "sysRst",function(ret){
			console.log(ret);
		});
		return true;
	}else{
		
		return false;
	}
});

$("#info").click(function(){
	if (window.confirm('CSDN Tyrion.Mon')){
		
		return true;
	}else{
		
		return false;
	}
});


$("#localName").click(function(){
	var name = prompt('NAME');
	if (name != null && name != '') {
		$.post("/rst", "localName:" + name + ',', function(ret){

		});
	}
});
$("#severIP").click(function(){
	var name = prompt('IP');
	if (name != null && name != '') {
		$.post("/rst", "serverIP:" + name + ',', function(ret){

		});
	}
});
$("#severPORT").click(function(){
	var name = prompt('端口');
	if (name != null && name != '') {
		$.post("/rst", "serverPORT:" + name + ',', function(ret){

		});
	}
});
$("#ntpService").click(function(){
	var name = prompt('输入新的NTP服务器');
	if (name != null && name != '') {
		$.post("/ntp", "ntpService:" + name + ',', function(ret){

		});
	}
});
$("#getTimexHour").click(function(){
	var name = prompt('请输入分钟数（范围 1 ~ 65535）');
	if (name != null && name != '') {
		$.post("/ntp", "getTimexHour:" + name + ',', function(ret){

		});
	}
});
setInterval(function(){
	if (document.getElementById('ntpSetLi')) {	//仅该页面显示时		
		$.get("/ntp", "",function(ret){
			console.log(ret +' len=' + ret.length);
			var valArr = ret.split(',');
			for (var i = 0; i < valArr.length; i++)
			{
				switch (i)
				{
					case 0: $('#ntpServiceP').text(valArr[i]); break;
					case 1: $('#getTimexHourP').text(valArr[i]); break;

				}
			}
		});
	}
}, 1000);

